package ${package.Controller};

import java.util.List;
import javax.annotation.Resource;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.chinaictc.framework.core.response.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import ${package.Service}.${table.serviceName};
import ${package.Entity}.${entity};

<#if restControllerStyle>
import org.springframework.web.bind.annotation.RestController;
<#else>
import org.springframework.stereotype.Controller;
</#if>
<#if superControllerClassPackage??>
import ${superControllerClassPackage};
</#if>

/**
 * ${table.comment!} 前端控制器
 * @author ${author}
 * @date ${date}
 */
@Slf4j
<#if restControllerStyle>
@RestController
<#else>
@Controller
</#if>
@RequestMapping("<#if controllerMappingHyphenStyle??>${controllerMappingHyphen}<#else>${table.entityPath}</#if>")
<#if kotlin>
class ${table.controllerName}<#if superControllerClass??> : ${superControllerClass}()</#if>
<#else>
<#if superControllerClass??>
public class ${table.controllerName} extends ${superControllerClass} {
<#else>
public class ${table.controllerName} {
</#if>
    <#list table.fields as field>
        <#if field.keyFlag><#--生成主键排在第一位-->
            <#assign pkName = field.propertyName>
            <#assign pkType = field.propertyType>
        </#if>
    </#list>
    <#assign service = table.serviceName?uncap_first>

    @Resource
    private ${table.serviceName} ${service};

    @GetMapping(value = "/{id}")
    public Result get(@PathVariable ${pkType} id) {
            return Result.success(${service}.getById(id));
    }

    @PostMapping(value = "/save")
    public void save(@RequestBody ${entity} entity) {
        ${service}.save(entity);
    }

    @PostMapping(value = "/remove")
    public void remove(@RequestBody List<${pkType}> ids) {
        ${service}.removeByIds(ids);
    }

    @GetMapping(value = "/update")
    public void update(@RequestBody ${entity} entity) {
        ${service}.updateById(entity);
    }

    @GetMapping(value = "/list")
    public Result list() {
        return Result.success(${service}.list());
    }

    @GetMapping(value = "/page")
    public Result page(Page<${entity}> page) {
        QueryWrapper<${entity}> queryWrapper = new QueryWrapper<>();
        return Result.success(${service}.page(page, queryWrapper));
    }

}
</#if>